use strict;
use warnings;

my $print_swings = 0;
my $argnum;
my $no_header = 0;

foreach $argnum (0 .. $#ARGV) {
	$print_swings = 1 if ( "$ARGV[$argnum]" =~ /printswings/ );
	$no_header = 1 if ( "$ARGV[$argnum]" =~ /noheader/ );
}

#sim variables
my $sim_time = 8640000; #number of seconds in simulation 86400 = 1 day
my $player_swing_speed = 3.5;
my $boss_swing_speed = 2.4;
my $player_dodge_start = 0.0;
my $player_dodge_end = 0.40;
my $player_parry_start = 0.25;
my $player_parry_end = 0.25;

#begins simulation - timers are in tenths of seconds
print "Dodge Chance\tParry Chance\tBoss Swings\tDodges\tParries\tPlayer Swings\tRune Strikes\tHasted Swings\n";
for (my $player_dodge_chance = $player_dodge_start; $player_dodge_chance <= $player_dodge_end; $player_dodge_chance += 0.01) {
for (my $player_parry_chance = $player_parry_start; $player_parry_chance <= $player_parry_end; $player_parry_chance += 0.01) {
	my $next_pswing = 0;
	my $next_bswing = 0;
	my $dodges = 0;
	my $parries = 0;
	my $runestrikes = 0;
	my $pswings = 0;
	my $bswings = 0;
	my $parry_hastes = 0;
	my $haste = 0;
	my $rs_proc = 0;
	while (($next_bswing <= $sim_time) and ($next_pswing <= $sim_time)) {
		if ($next_bswing <= $next_pswing) {
			my $rng = rand();
			if ($rng <= $player_dodge_chance) {
				$dodges++; 
				$rs_proc = 1;
				print "$next_bswing\tbSwing\tdodge\n" if ($print_swings);
			} elsif  ($rng <= ($player_parry_chance + $player_dodge_chance)) {
				$parries++;
				$haste = 1;
				$rs_proc = 1;
				$next_pswing -= $player_swing_speed*0.4 if ($next_pswing - $next_bswing >= $boss_swing_speed*0.6);
				$next_pswing = $next_bswing + $player_swing_speed*0.2 if (($next_pswing - $next_bswing < $boss_swing_speed*0.6) and ($next_pswing - $next_bswing > $boss_swing_speed*0.2));
				print "$next_bswing\tbSwing\tparry\n" if ($print_swings);
			} else {
				print "$next_bswing\tbSwing\thit/miss\n" if ($print_swings);
			}
			$bswings++;
			$next_bswing += $boss_swing_speed;
		}
		if ($next_pswing < $next_bswing) {
			if ($rs_proc) {
				$runestrikes++;
				$rs_proc = 0;
				print "$next_pswing\tpSwing\tRune Strike" if ($print_swings);
			} else {
				print "$next_pswing\tpSwing\tSwing" if ($print_swings);
			}
			if ($haste) {
				$haste = 0;
				print "\tHasted" if ($print_swings);
			}
			print "\n" if ($print_swings);
			$pswings++;
			$next_pswing += $player_swing_speed;
		}
	}
	print "$player_dodge_chance\t$player_parry_chance\t$bswings\t$dodges\t$parries\t$pswings\t$runestrikes\t$parry_hastes\n" unless ($print_swings);
}
}
